﻿<local:BaseLab x:Class="Rxx.Labs.Reactive.UI.ObservableSyndicationLab"
							 xmlns:local="clr-namespace:Rxx.Labs"
							 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
							 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
							 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
							 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
							 xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
							 mc:Ignorable="d" 
							 d:DesignHeight="300" d:DesignWidth="300"
							 DataContext="{Binding RelativeSource={RelativeSource Self}}">

	<local:BaseLab.Resources>
		<CollectionViewSource x:Key="Feed" Source="{Binding Feed}">
			<CollectionViewSource.SortDescriptions>
				<cm:SortDescription PropertyName="Value.LastUpdatedTime" Direction="Descending" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>
	</local:BaseLab.Resources>

	<DockPanel>
		<StackPanel DockPanel.Dock="Top">
			<StackPanel.Resources>
				<Style x:Key="Panel" TargetType="FrameworkElement">
					<Setter Property="Margin" Value="5" />
				</Style>
				<Style TargetType="StackPanel" BasedOn="{StaticResource Panel}" />
				<Style TargetType="Grid" BasedOn="{StaticResource Panel}" />
				<Style TargetType="RadioButton">
					<Setter Property="Margin" Value="8" />
				</Style>
				<Style TargetType="Button">
					<Setter Property="Padding" Value="4" />
				</Style>
				<Style TargetType="TextBox">
					<Setter Property="VerticalAlignment" Value="Center" />
				</Style>
			</StackPanel.Resources>

			<DockPanel>
				<Label DockPanel.Dock="Left" Target="{Binding ElementName=FeedTextBox}" Content="Feed: " />
				<TextBox Name="FeedTextBox" Text="{Binding FeedUrl, ValidatesOnExceptions=True}" />
			</DockPanel>

			<StackPanel Orientation="Horizontal">
				<RadioButton GroupName="Format" Content="RSS 2.0" IsChecked="{Binding IsFormatRss}" />
				<RadioButton GroupName="Format" Content="Atom 1.0" IsChecked="True" />
			</StackPanel>

			<DockPanel>
				<Label DockPanel.Dock="Left" Target="{Binding ElementName=AutoDownloadIntervalTextBox}" Content="Auto refresh (hh:mm:ss:): " />
				<TextBox Name="AutoDownloadIntervalTextBox" Text="{Binding AutoRefreshInterval, ValidatesOnExceptions=True}" />
			</DockPanel>

			<Grid>
				<Button Name="ApplySettingsButton" Content="Apply Settings"
								VerticalAlignment="Center" HorizontalAlignment="Center"
								Click="ApplySettingsButton_Click" />
			</Grid>

			<TextBlock FontWeight="Bold">
				<TextBlock Text="{Binding Count, Source={StaticResource Feed}}" />
				<Run Text=" Item(s)" />
			</TextBlock>
		</StackPanel>

		<ListBox ItemsSource="{Binding Source={StaticResource Feed}}">

			<ListBox.ItemContainerStyle>
				<Style TargetType="ListBoxItem">
					<Setter Property="Padding" Value="8" />
				</Style>
			</ListBox.ItemContainerStyle>

			<ListBox.ItemTemplate>
				<DataTemplate>

					<StackPanel>
						<TextBlock Text="{Binding Value.LastUpdatedTime}" />
						<TextBlock Text="{Binding Value.Title.Text}" FontWeight="Bold" />
						<TextBlock Text="{Binding Value.Links[0].Uri}" />
						<TextBlock Text="{Binding Value.Content.Text}" MaxHeight="50" TextTrimming="CharacterEllipsis" />
					</StackPanel>

				</DataTemplate>
			</ListBox.ItemTemplate>

		</ListBox>

	</DockPanel>

</local:BaseLab>